package com.xs.aifitnessagent.config;

import com.xs.aifitnessagent.rag.AppDocumentLoader;
import jakarta.annotation.Resource;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *  向量存储配置类（初始化基于内存的向量数据库 Bean）
 *  构造一个 VectorStore 对象，用于存储和检索向量数据
 *
 * @author lambor
 */
@Configuration
public class AppVectorStoreConfig {

    @Resource
    private AppDocumentLoader appDocumentLoader;

    @Bean
    VectorStore appVectorStore(EmbeddingModel dashscopeEmbeddingModel) {
        SimpleVectorStore simpleVectorStoreBuilder = SimpleVectorStore.builder(dashscopeEmbeddingModel).build();
        simpleVectorStoreBuilder.add(appDocumentLoader.loadMarkdowns());
        return simpleVectorStoreBuilder;
    }
}
